package kaixo;

public class Paquete {
	private byte[] pdu;
	//byte source;
	//byte destino;
	//byte nundik;
	//byte action;
	//byte[] data;
	boolean ackReturned=false;
	boolean waitingForResponse=false;
	

	public Paquete(byte[] nPdu){
		this.pdu = new byte[nPdu.length];
		for(int i=0; i<(nPdu.length);i++){
			this.pdu[i] = nPdu[i];
		}/*
		this.source = nPdu[8];
		this.destino = nPdu[9];
		this.nundik = nPdu[10]; 
		this.action = nPdu[11];*/
		/*if(nPdu.length>12){
			this.data = new byte[(nPdu.length-12)];
			for(int i=0; i<(nPdu.length-12);i++){
				this.data[i] = nPdu[12+i];
			}
		}*/
	}
	
	public boolean isWaitingForResponse() {
		return waitingForResponse;
	}

	public void setWaitingForResponse(boolean waitingForResponse) {
		this.waitingForResponse = waitingForResponse;
	}

	public boolean isAckReturned() {
		return ackReturned;
	}

	public void setAckReturned(boolean ackReturned) {
		this.ackReturned = ackReturned;
	}

	public byte[] getPdu() {
		return pdu;
	}

	public void setPdu(byte[] pdu) {
		this.pdu = pdu;
	}
	
	public byte getSource() {
		return this.pdu[8];
	}

	public void setSource(byte source) {
		this.pdu[8] = source;
	}

	public byte getDestino() {
		return this.pdu[9];
	}

	public void setDestino(byte destino) {
		this.pdu[9] = destino;
	}

	public byte getNundik() {
		return this.pdu[10];
	}

	public void setNundik(byte nundik) {
		this.pdu[10] = nundik;
	}

	public byte getAction() {
		return this.pdu[11];
	}

	public void setAction(byte action) {
		this.pdu[11] = action;
	}

	public byte[] getData() {
		byte[] data = new byte[this.pdu.length-12];
		if(pdu.length>12){
			for(int i=0;i<(this.pdu.length-12);i++){
				data[i] = this.pdu[i+12];
			}
		} else {
			return null;
		}		
		return data;
	}

	public void setData(byte[] data) {
		for(int i=0;i<(this.pdu.length-12);i++){
			this.pdu[i+12] = data[i];
		}
	}

	
}
